//
//  LZCouponDetailTopCell.m
//  laziz_Merchant
//
//  Created by xbnzd on 16/12/20.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZCouponDetailTopCell.h"
#import "GiftListLabel.h"
#import "LZCouponListModel.h"
#import "LZDateFormatterManager.h"

@interface LZCouponDetailTopCell()
@property (weak, nonatomic) IBOutlet GiftListLabel *couponTitleLabel;  //title
@property (weak, nonatomic) IBOutlet UILabel *couponsToIssueLabel;  //总共发放
@property (weak, nonatomic) IBOutlet UILabel *couponsToIssueCountLabel; //总共发放张数
@property (weak, nonatomic) IBOutlet UILabel *couponsRemainLabel;  //剩余
@property (weak, nonatomic) IBOutlet UILabel *couponsRemainCountLabel;  //剩余张数
@property (weak, nonatomic) IBOutlet UILabel *couponsTimeRemainLabel;   //剩余时间
@property (weak, nonatomic) IBOutlet UILabel *couponsTimeRemainTimeLabel;  //时间


@end

@implementation LZCouponDetailTopCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    _couponsToIssueLabel.text = LZLocalizedString(@"coupons_to_issue", nil);
    _couponsRemainLabel.text = LZLocalizedString(@"quatity_remaining", nil);
    _couponsTimeRemainLabel.text = LZLocalizedString(@"time_remaining", nil);
    self.couponTitleLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
}

- (void)loadContentWithData:(LZCouponListModel *)dataModel
{
    [self setTitleContentLabelText:dataModel.couponsName];
    self.couponsToIssueCountLabel.text = [NSString stringWithFormat:@"%d",dataModel.couponsTotalCount];
    self.couponsRemainCountLabel.text = [NSString stringWithFormat:@"%d",dataModel.couponsTotalCount - dataModel.couponsGetCount];
    self.couponsTimeRemainTimeLabel.text = [[LZDateFormatterManager shareInstance] returnRemainingHMTimeWithEndTime:dataModel.couponsEndTime];
}

- (void)setTitleContentLabelText:(NSString *)text
{
    if (text.length <= 0) {
        return;
    }
    extern CGFloat textLineSpace;
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    
    [style setLineSpacing:textLineSpace];
    [style setLineBreakMode:NSLineBreakByWordWrapping];
    [style setAlignment:NSTextAlignmentNatural];
    
    [attStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, attStr.length)];
    self.couponTitleLabel.attributedText = attStr;
}

#pragma mark -
#pragma mark action
- (void)configureLabel
{
    [self.couponTitleLabel setVerticalAlignment:VerticalAlignmentTop];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
